<template>
	<view :data-theme="themeStyle">
<!-- 		<scroll-view id="tab-bar" class="order-nav" :scroll-x="true" :show-scrollbar="false" :scroll-into-view="scrollInto">
			<view v-for="(statusItem, statusIndex) in statusList" :key="statusIndex" class="uni-tab-item" :id="statusItem.id" :data-current="statusIndex" @click="ontabtap">
				<text class="uni-tab-item-title" :class="statusIndex == orderStatus ? 'uni-tab-item-title-active' : ''">{{ statusItem.name }}</text>
			</view>
		</scroll-view> -->
		<mescroll-uni @getData="getData" ref="mescroll">
			<block slot="list">
				<!-- 明细列表 -->
				<view class="balances" v-if="dataList.length" v-for="(item, index) in dataList" :key="index">
					<image :src="$util.img('upload/uniapp/member/balance_detail/income.png')" mode="" class="balances-img" v-if="item.account_data>0"></image>
					<image v-else :src="$util.img('upload/uniapp/member/balance_detail/pay.png')" mode="widthFix"></image>
					<view class="balances-info">
						<text>{{ item.type_name }}</text>
						<text>{{ item.remark }}</text>
						<text>{{ $util.timeStampTurnTime(item.create_time) }}</text>
					</view>
					<view class="balances-num">
						<text :class="item.account_data>0? 'ns-text-color':''">{{item.account_data>0? '+'+item.account_data : item.account_data }}</text>
					</view>
				</view>
				<!-- 无明细列表 -->
				<view v-else><ns-empty></ns-empty></view>
			</block>
		</mescroll-uni>
		<loading-cover ref="loadingCover"></loading-cover>
		<ns-show-toast></ns-show-toast>
	</view>
</template>

<script>
import globalConfig from '@/common/js/golbalConfig.js'
import nsShowToast from '@/components/ns-show-toast/ns-show-toast.vue'
export default {
	data() {
		return {
			dataList: [],
			statusList:[
				{name:'全部',id:'0'},
				{name:'收入',id:'1'},
				{name:'支出',id:'2'}
			],
			scrollInto: '',
			orderStatus: '0',
		};
	},
	components: {
		nsShowToast
	},
	mixins: [globalConfig],
	onLoad(option) {
		if (option.status) this.orderStatus = option.status;
	},
	onShow() {
		// 刷新多语言
		this.$langConfig.refresh();
		if (!uni.getStorageSync('token')) {
			this.$refs.login.open('/otherpages/member/balance/balance');
		}
	},
	methods: {
		ontabtap(e) {
			let index =e.currentTarget.dataset.current;
			this.orderStatus = this.statusList[index].id;
			this.$refs.mescroll.refresh();
		},
		getData(mescroll) {
			this.$api.sendRequest({
				url: '/api/memberaccount/page',
				data: {
					page_size: mescroll.size,
					page: mescroll.num,
					account_type: 'balance,balance_money'
				},
				success: res => {
					let newArr = [];
					let msg = res.message;
					if (res.code == 0 && res.data) {
						newArr = res.data.list;
					} else {
						this.$util.showToast({ title: msg });
					}
					mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(newArr); //追加新数据
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					mescroll.endErr();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
	}
};
</script>

<style lang="scss">
	.order-nav {
		width: 100vw;
		height: 70rpx;
		display: flex;
		flex-direction: row;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
		background: #fff;
		border-bottom-left-radius: 24rpx;
		border-bottom-right-radius: 24rpx;
		padding-bottom: 30rpx;
		position: fixed;
		left: 0;
		z-index: 998;
			
		.uni-tab-item {
			width: 33.33%;
			text-align: center;
			/* #ifndef APP-PLUS */
			display: inline-block;
			/* #endif */
			flex-wrap: nowrap;
		}
	
		.uni-tab-item-title {
			color: #555;
			font-size: $ns-font-size-lg;
			display: block;
			height: 64rpx;
			line-height: 64rpx;
			border-bottom: 2px solid #fff;
			padding: 0 10rpx;
			flex-wrap: nowrap;
			/* #ifndef APP-PLUS */
			white-space: nowrap;
			/* #endif */
		}
	
		.uni-tab-item-title-active {
			display: block;
			height: 64rpx;
			padding: 0 10rpx;
		}
		
		::-webkit-scrollbar {
		  width: 0;
		  height: 0;
		  color: transparent;
		}
	}
	.balances {
		width: 702rpx;
		border-radius: 10rpx;
		margin: 0 auto;
		padding: 27rpx 27rpx;
		box-sizing: border-box;
		display: flex;
		align-items: flex-start;
		background: #fff;
		margin-bottom: 18rpx;
		margin-top: 18rpx;
		image {
			width: 54rpx;
			height: 54rpx;
			border-radius: 50%;
		}
		.balances-info {
			flex: 1;
			margin-left: 16rpx;
			display: flex;
			flex-direction: column;
			text {
				line-height: 1;
				&:last-child {
					font-size: $ns-font-size-lg;
				}
				&:nth-child(2) {
					margin-top: 18rpx;
					font-size: $ns-font-size-x-sm;
					color: #A9A9A9;
				}
				&:nth-child(3) {
					font-size: $ns-font-size-x-sm;
					margin-top: 19rpx;
					color: #A9A9A9;
				}
			}
		}
		.balances-num {
			text {
				line-height: 1;
				font-size: $ns-font-size-x-lg;
				color: #000;
			}
		}
	
	}
	
	.empty {
		width: 100%;
		height: 500rpx;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
	
		.iconfont {
			color: $base-color;
			font-size: 50rpx;
			margin-bottom: $ns-margin;
		}
	}


</style>
